package com.seewo.dubbo.debugger.sample.consumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.seewo.dubbo.debugger.api.ApiDebuggerService;
import com.seewo.dubbo.debugger.api.Arg;
import com.seewo.dubbo.debugger.api.Request;
import com.seewo.dubbo.debugger.sample.api.DemoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author chenliangliang
 * @date 2018/7/24
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Reference(version = "1.0")
    private DemoService demoService;

    @Reference(version = "1.0.0")
    private ApiDebuggerService apiDebugerService;

    @GetMapping("/{name}")
    public String test(@PathVariable("name")String name){
        demoService.sayHello(name);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"  Hello: "+name;
    }

    @GetMapping("/doc")
    public Object getDoc(){
        return apiDebugerService.getDocs();
    }

    @GetMapping("/debug")
    public Object debug(){
        Request request=new Request();
        request.setInterfaceName("com.seewo.dubbo.debugger.sample.api.UserService");
        request.setMethodName("getUserById");
        Arg arg=new Arg();
        arg.setClassName("java.lang.Integer");
        arg.setName("id");
        arg.setValue("1");
        arg.setType("integer");
        arg.setIndex(0);
        request.addArg(arg);
        return apiDebugerService.debug(request);
    }

}
